package com.LeeCode;

/**
 * 单值二叉树
 */

public class Code965 {
    public static void main(String[] args) {
        Integer[] arr = {1, 1, 2, 1, 1, null, 1};
        TreeNode root = Utils.buildTree(arr);
        System.out.println(new Code965().isUnivalTree(root));
    }

    public boolean isUnivalTree(TreeNode root) {
        if (root == null) return true;
        return dfs(root, root.val);
    }

    public boolean dfs(TreeNode root, int val) {
        if (root == null) return true;
        if (root.val != val) return false;
        return dfs(root.left, val) && dfs(root.right, val);
    }
}
